<?php namespace system\model;

use houdunwang\model\Model;

class Config extends Model
{
    //数据表
    protected $table = "config";

    //允许填充字段
    protected $allowFill = [];

    //禁止填充字段
    protected $denyFill = [];

    //自动验证
    protected $validate = [
        //['字段名','验证方法','提示信息',验证条件,验证时间]
    ];

    //自动完成
    protected $auto = [
        //['字段名','处理方法','方法类型',验证条件,验证时机]
    ];

    //自动过滤
    protected $filter = [
        //[表单字段名,过滤条件,处理时间]
    ];

    //时间操作,需要表中存在created_at,updated_at字段
    protected $timestamps = true;
    /*
     * 系统配置
     */
    public function setConfig($post){
        $model = Config::find(1);
        if(!$model){
            $model = new static();
        }
        $model->system = json_encode($post,JSON_UNESCAPED_UNICODE);
        $model->save();
    }
    /*
     * 微信token
     */
    public function setWeixinConfig($post){
//        查找主键=1数据
        $model = Config::find(1);
        if(!$model) {
            //数据表找不到id=1数据，执行添加
            $model = new static();
        }
        $model->weixin = json_encode($post,JSON_UNESCAPED_UNICODE);
//        p($model['weixin']);die;
        $model->save();
    }
}